<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组去重</title>
</head>
<body>
  <script>
    Array.prototype.distinct = function (){
      var arr = this,
        len = arr.length;
      arr.sort(function(a,b){  //对数组进行排序才能方便比较
        return a - b;
      })
      function loop(index){
        if(index >= 1){
          if(arr[index] === arr[index-1]){
            arr.splice(index,1);
          }
          loop(index - 1); //递归loop函数进行去重
        }
      }
      loop(len-1);
      return arr;
    };
    var nums = [1,5,4,4,7,6,6];
     var num=nums.distinct();
    console.log(num.toString());
  </script>
</body>
</html>
